package main

import (
	"fmt"
	"strings"
)

// 动态返回追加前缀的函数

func MakeAddPrefix(pre string) func(string) string {
	return func(s string) (r string) {
		r = s
		if !strings.HasPrefix(s, pre) {
			r = pre + r
		}
		return
	}
}

func main() {
	addGo := MakeAddPrefix("go-")
	addJava := MakeAddPrefix("java-")
	fmt.Println("lang add prefix 'go': ", addGo("lang"))
	fmt.Println("lang add prefix 'java': ", addJava("lang"))
}
